# 公共断言
import json

from parameterized import param

import config

# 公共断言
def common_assert(case,response_json,testexpect="操作成功"):
    case.assertEqual(testexpect, response_json.get("message"))

# 批量创建数据
def BData(mobile_no,count):
    file = config.BASE_DIR+"/data/mobile_no.json"
    with open(file,"r", encoding="utf-8") as f:
        data = json.load(f)

    data["mobile_no"] = []
    for i in range(count):
        data["mobile_no"].append(str(mobile_no))
        mobile_no += 1

    with open(file,"w",encoding="utf-8") as f:
        json.dump(data,f,ensure_ascii=True,indent=4)

def buildData():
    testdata = []
    file = config.BASE_DIR+"/data/params.json"
    with open(file,encoding="utf-8") as f:
        receivedata = json.load(f)
        for i in receivedata:
            param = i.get("param")
            testexpect = i.get("testexpect")
            testdata.append((param,testexpect))
        print(testdata)
        return testdata

#三目运算符
# age = 12
# result = "成年人" if age >= 18 else "未成年"
# print(result)

#列表推导式
# list = [1,2,3,4,5,6]
# [print(i) for i in list]
# list2 = []
# [list2.append(i) for i in range(1,6)]
# print(list2)

# 匿名函数
# li = [1,2,3,4]
# fun = list(map(lambda x:x*3,li))
# print(fun)

#主动抛出异常
# def login():
#     pwd = input("请输入密码：")
#     if len(pwd) >= 6:
#         return "密码长度正确"
#     raise Exception("密码长度不够，请重新输入")
#
# try:
#     print(login())
# except Exception as e:
#     print(e)
#------------------------------------------------

#单例模式
# class single(object):
#     obj = None
#     def __new__(cls,*args,**kwargs):
#         if cls.obj == None:
#             cls.obj = super().__new__(cls)
#         print("重写new函数")
#         return cls.obj
#     def __init__(self):
#         print("初始化实例")
#
# sa =single()
# print(sa)
#
# sa2 = single()
# print(sa2)
#----------------------------------------